package com.PengGoBook.main.ui;

import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import com.PengGoBook.main.R;
import com.PengGoBook.main.utils.ImageUtil;
import com.PengGoBook.main.utils.IntentUtil;
import org.apache.http.message.BasicNameValuePair;
import org.codehaus.jackson.map.ObjectMapper;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created with IntelliJ IDEA.
 * User: S7
 * Date: 13-5-29
 * Time: 上午9:55
 * To change this template use File | Settings | File Templates.
 */
public abstract class BaseListFragment extends Fragment implements
        XListView.IXListViewListener {

//    protected XListView listview;
    protected GridView gridView;
    protected View view;
    LayoutInflater mInflater;
    protected boolean mIsScroll = false;
    ObjectMapper mMapper = new ObjectMapper();
    protected BaseAdapter mAdapter;

    public ExecutorService executorService = Executors.newFixedThreadPool(5);

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        mInflater = inflater;
        view = inflater.inflate(R.layout.main, null);
        gridView = (GridView) view.findViewById(R.id.gridview);
        initListView();
//        listview.setPullLoadEnable(true);
//        listview.setPullRefreshEnable(false);
        return super.onCreateView(inflater, container, savedInstanceState);
    }

    private void initListView() {
    }

    public void startDetailActivity(Activity mContext, String url,
                                    String title, String shareTitle) {
//        IntentUtil.start_activity(mContext, DetailsActivity.class,
//                new BasicNameValuePair("url", url), new BasicNameValuePair(
//                "title", title), new BasicNameValuePair("sharetitle",
//                shareTitle));
    }

    protected void onLoad() {
//        listview.stopRefresh();
//        listview.stopLoadMore();
//        listview.setRefreshTime("刚刚");
    }

    ImageUtil.ImageCallback callback1 = new ImageUtil.ImageCallback() {

        @Override
        public void loadImage(Bitmap bitmap, String imagePath) {
            // TODO Auto-generated method stub
            try {
                ImageView img = (ImageView) gridView.findViewWithTag(imagePath);
                img.setImageBitmap(bitmap);
            } catch (NullPointerException ex) {
                Log.e("error", "ImageView = null");
            }
        }
    };

}
